package com.heqiang.spring.factory;

import com.heqiang.spring.BeansException;
import com.heqiang.spring.config.BeanDefinition;

public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements BeanFactory {


    @Override
    public Object getBean(String name) throws BeansException {
        //先从单例里拿，有就直接返回
        Object singleton = getSingleton(name);
        if (singleton != null) {
            return singleton;
        }
        //单例容器里没有就新增一个
        BeanDefinition beanDefinition = getBeanDefinition(name);
        return createBean(name,beanDefinition);
    }

    protected abstract BeanDefinition getBeanDefinition(String name) throws BeansException;

    protected abstract Object createBean(String name,BeanDefinition beanDefinition) throws BeansException;
}
